import {Component,Input} from '@angular/core';
import {NavController} from 'ionic-angular';

import {addTrenchPage} from './addTrench/addTrench';
//引入产品信息页面
import {productPage} from './addTrench/inexistDealer/productPage/productPage'
import {ModalController} from 'ionic-angular';

//  http
import {Http,Headers} from '@angular/http';
import {interfaceUrls} from '../../provider/serverUrls';	//没有真实数据暂时不需要引入接口
import 'rxjs/add/operator/toPromise';
import 'rxjs/add/operator/timeout';

@Component({
  selector: 'page-contact',
  templateUrl: 'contact.html'
})
export class ContactPage {

    dealerInfo={};
    items=[];
    items2=[];
    items3=[];
    
    param={};
    param2={
					"keyword":"",
					"productId":""
			};
		param3={
				"keyword":"",
				"productId":""
		};
		pet: string = "收货渠道";
		public headers = new Headers({'Content-Type':'application/json;chartset=utf-8'});
    
    constructor(
	    	public navCtrl: NavController,
	    	public http:Http,
			public modalCtrl: ModalController

	)
    			{
   					}
 //添加经销商账户
    addTrench() {
            //将输入框中的产品信息数据传递给addTrenchPage页面
						this.http
            .post(interfaceUrls.repertoryList, JSON.stringify(this.param), {headers: this.headers})
         		.timeout(2000)
            .toPromise()
            .then(response =>{ 
			      	 console.info(response.json().infoData.items)
				    	 this.items = response.json().infoData.items;
				    	 this.navCtrl.push(addTrenchPage,
				    	 	{product:this.items}
				    	 );

			      })
			      .catch(
			      	err => {
				    		console.log('err');
				  			}
			      );
			      
        }
    ngAfterViewInit(){
    	//input输入框中的数据
    		this.http
            .post(interfaceUrls.repertoryList, JSON.stringify(this.param), {headers: this.headers})
         		.timeout(2000)
            .toPromise()
            .then(response =>{ 
			      	 console.info(response.json().infoData.items)
				    	 this.items = response.json().infoData.items;
			      })
			      .catch(
			      	err => {
				    		console.log('err');
				  			}
			      );
      //查询数据
        	this.http
				  .post(interfaceUrls.dealerReceive, JSON.stringify(this.param2), {headers: this.headers})
				  .timeout(2000) 	
				  .toPromise()
				  .then(response =>{ 
				  	console.info(response.json().infoData.items)
				    this.items2 = response.json().infoData.items;
				  })
				  .catch(
				  	err => {
				    		console.log('err');
				  			}
				  );
       }   
    dealerDeliver(){
    		this.http
				  .post(interfaceUrls.dealerDeliver, JSON.stringify(this.param3), {headers: this.headers})
				  .timeout(2000) 	
				  .toPromise()
				  .then(response =>{ 
				  	console.info(response.json().infoData.items)
				    this.items3 = response.json().infoData.items;
				  })
				  .catch(
				  	err => {
				    		console.log('err');
				  			}
				  );
    }
	openModal(characterNum) {

		let modal = this.modalCtrl.create(productPage, {product: this.items});
		modal.present();
	}
}
